<template>
  <div>
    <!-- <h3>这是图片分享页面</h3> -->

    <!-- 顶部活动导航栏 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <span
            v-for="item in photolist"
            :key="item.id"
            :class="['mui-control-item', item.id === 0 ? 'mui-active' : '']"
            data-wid="tab-top-subpage-1.html"
            @click="getphotobylist(item.id)"
          >
            {{ item.title }}
          </span>
        </div>
      </div>
    </div>

    <!--  图片的列表区  -->
    <ul class="lazyul">
      <router-link tag="li" v-for="item in photolistbyid" :key="item.id" :to="'/home/photoinfo/'+item.id">
        <img v-lazy="item.img_url" />
        <div class="inf">
          <h1 class="info-title">{{ item.title }}</h1>
          <div class="info-contain" v-html="item.content"></div>
        </div>
      </router-link>
    </ul>
  </div>
</template>



<script>
import mui from "../../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      photolist: [],
      photolistbyid: [],
    };
  },
  created() {
    this.getphotolist(), 
    this.getphotobylist(0);
  },
  methods: {
    async getphotolist() {
      //获取图标头部导航栏对应的id
      const { data } = await this.$http.get("/api/getimgcategory");
      if (data.status === 0) {
        data.message.unshift({ title: "全部", id: 0 });
        this.photolist = data.message;
      }
    },
    async getphotobylist(id) {
      //通过id获取对应页面的图片列表
      const result = await this.$http.get("/api/getimages/"+id);
      if (result.data.status === 0) {
        if(result.data.message.length === 0)
        {
          alert('没有东西')
        }
        this.photolistbyid = result.data.message;
        console.log(this.photolistbyid)
      }
    },
    
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
};
</script>

<style lang="scss" scoped>
.mui-slider {
  touch-action: pan-x;
}

img[lazy="loading"] {
  width: 40px;
  height: 300px;
  margin: auto;
  list-style: none;
}
.lazyul {
  background-color: white;
}

ul {
  margin: 0px;
  padding: 0;
  text-align: center;
  padding: 10px;
  li {
    box-shadow: 0 0 7px gray;
    position: relative;
    & + li {
      margin-top: 10px;
    }
    .inf {
      height: 120px;
      overflow:scroll ;
      position: absolute;
      bottom: 0;
      color:honeydew ;
      background-color: rgba(128, 128, 128, 0.5) ;
      h1 {
        font-size: 14px;
      }
      .info-contain {
        font-size: 13px;
      }
    }
  }
  img {
    vertical-align: middle;
    width: 100%;
  }
}
</style>
